package com.ttloner.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ttloner.admin.bean.User;
import com.ttloner.admin.bean.UserShow;
import com.ttloner.admin.mapper.UserMapper;
import com.ttloner.admin.mapper.UserShowMapper;
import com.ttloner.admin.service.UserShowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * @author TTLoner
 * @date 2021/7/19 21:59
 * @description
 */
@Controller
public class TableController {
    @Autowired
    private UserShowService userShowService;
    @GetMapping("/basicTable")
    public String basicTable(){
        return "/table/basic_table";
    }
    @GetMapping("/dynamicTable")
    public String dynamicTable(Model model, @RequestParam(value = "pg",defaultValue = "1") Integer pg){
//        List<UserShow> users= userShowService.list();
//        model.addAttribute("users",users);
        Page<UserShow> page = new Page<>(pg,2);
        Page<UserShow> page1 = userShowService.page(page, null);
        model.addAttribute("page",page1);
//        List<User> users = new ArrayList<>();
//        users.add(new User("张三","李四"));
//        users.add(new User("王五","赵六"));
//        model.addAttribute("users",users);
        return "/table/dynamic_table";
    }
    @GetMapping("/responsiveTable")
    public String responsiveTable(){
        return "/table/responsive_table";
    }
    @GetMapping("/editableTable")
    public String editableTable(){
        return "/table/editable_table";
    }
    @GetMapping("/delete")
    public String deleteById(@RequestParam(value = "id") Integer id, @RequestParam(value = "pg") Integer pg){
        userShowService.removeById(id);
        return "redirect:/dynamicTable?pg="+pg;
    }
}
